package top.hkyzf.study.leetcode.dp;

import org.junit.Test;

import java.util.Arrays;

/**
 * description:
 *
 * @author zhufeng
 * @version 1.0
 * @date 2024-3-24 14:10
 */
public class 零钱兑换_322 {
    public int coinChange(int[] coins, int amount) {
        int max = amount + 1;
        int[] dp = new int[max];
        Arrays.fill(dp, max);
        dp[0] = 0;
        for (int i = 1; i < max; i++) {
            for (int coin : coins) {
                if (coin <= i) {
                    dp[i] = Math.min(dp[i], dp[i - coin] + 1);
                }
            }
        }
        return dp[amount] == max ? -1 : dp[amount];
    }

    @Test
    public void testCoinChange () {
        int[] coins = {1, 2, 5};
        int amount = 11;
        System.out.println(coinChange(coins, amount));
    }
}
